<?php
include(dirname(__FILE__).'/top-bottom-share-data.php');

$dt = new DataTable(constant('DB_TABLE_WORKING'));
$GLOBALS['GV_IMAGE_PATH'] = 'working/';
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
if ( isset($_GET['id'])) {
	$condition = "`id`=".intval($_GET['id']);
}else{
	$condition = "`is_delete`='N'";
	
	if ( isset($_REQUEST['cat_id']) && $_REQUEST['cat_id'] > 0) {
		$condition .= sprintf(" AND `cat_id`=%d", $_REQUEST['cat_id']);
	}
}

$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0?intval($_REQUEST['page']):1;
$page_size = isset($_REQUEST['page_size'])?intval($_REQUEST['page_size']):5;
$offset = $page_size * ( $page - 1);
$GLOBALS['PAGE_LIST_DATA'] = $dt->get_list($condition, array('-date','-id'), $page_size, $offset);
$total_row =  $dt->get_count($condition);
$GLOBALS['PAGE_LIST_TOTAL_PAGE'] = ceil($total_row/$page_size);
$GLOBALS['PAGE_LIST_PAGE'] = $page;
$_REQUEST['page'] = $page;

$dt_img = new DataTable(constant('DB_TABLE_WORKING_IMG'));
foreach ( $GLOBALS['PAGE_LIST_DATA']  as $index=>$row){
	$condition = sprintf("`working_id`=%d", $row['id']);
	$GLOBALS['PAGE_LIST_DATA'][$index]['img_list'] = $dt_img->get_list($condition,'id',5);
}
#facebook graphic info
if ( isset($_REQUEST['vf']) && $_REQUEST['vf'] =='fb' ){
	$article_id = intval($_REQUEST['id']);
	$article_data = $dt->get($article_id);
	if ( $article_data)
	{
		$GLOBALS['META_FB_IMAGE'] = constant('SITE_URL_PATH').'/img/working/'.$article_data['img_path'];
		$GLOBALS['META_FB_TITLE'] = '[班尼頓寫真攝影] 作品分享, '.$row['title'];
		$GLOBALS['META_FB_URL'] =  constant('SITE_URL_PATH').'/working.php?vf=fb&id='.$article_data['id'];
	}
}
?>